<?php


class FaresDAO {
     function __construct($db) {
        $this->db=$db;
    }
    

    public function create(FaresTo $fares) {
		$db = $this->db;
                
                
$stmt = $db->prepare("INSERT INTO fares (value,description,date) VALUES (?, ?, ?)");
		

                $faresValue= $fares->getFares();
                $stmt->bindParam(1, $faresValue);
                
                $faresDescription=$fares->getDescription();
                $stmt->bindParam(2,$faresDescription);
               
                $faresDate= $fares->getDate();
		$stmt->bindParam(3, $faresDate);
                
                 $result=$stmt->execute();
                
              
                
               if($result){
                   return true;
               }else return 0;
               
	}
        
         public function update(FaresTo $fares) {
 
             $db = $this->db;
		$id=$fares->getId();
		$stmt = $db->prepare("update fares f SET
                    f.values=? ,f.description =?,f.date=? WHERE P.id=$id");
		
                 $id = $fares->getId();
                $stmt->bindParam(1, $id );
		
		$value = $fares->getFares();
                $stmt->bindParam(2, $value);
                
                $date=$stmt=$fares->getDate();
		$stmt->bindParam(3, $date);
               
                
                $result=$stmt->execute();
               
                
               if($result){
                   return true;
               }else return 0;
               
	}
        
        
        
        public function getById($id) {
           
		$park = null;
		$db = $this->db;
		
		$stmt = $db->prepare("selelct * from fares where id");
		$stmt->bindParam(1, $id);
		$stmt->execute();
		
		$row = $stmt->fetch();
		
		if(isset($row['id'])) {
			 $fares = new FaresTo();
                        $fares->setId($row['id']);
                        $fares->setFares($row['value']);
                        $fares->setDescription ($row['description']);
                        $fares->setDate($row['date']);
                        
                        
		}
		
		return $fares;
	}
             
             
             
         
         public function getList() {
		$faresall = array();
		$db = $this->db;
		
               
                $stmt = $db->prepare("select * from fares");
		$stmt->execute();
		$result = $stmt->fetchAll();
                
                
		if(sizeof($result) > 0) {
			foreach($result as $row) {
				
			
                        $fares = new FaresTo();
                        $fares->setId($row['id']);
                        $fares->setFares($row['value']);
                        $fares->setDescription ($row['description']);
                        $fares->setDate($row['date']);
                        
                        
                        $faresall[]=$fares;
                
                
		}
		
		
	}  
    return $faresall;
}
         
    
}

?>

